//
//  MapViewVC.m
//  Lrjh
//
//  Created by jun on 2025/7/22.
//

#import "MapViewVC.h"
#import <MapKit/MapKit.h>

@interface MapViewVC ()
@property (weak, nonatomic) MKMapView *mapView;
@end

@implementation MapViewVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"Location";
    MKMapView *mapView = [[MKMapView alloc] init];
    mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:mapView];
    
    self.mapView = mapView;
    [mapView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_offset(0);
    }];
    
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(self.lat, self.lon);
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(
        coordinate,
        1000,
        1000
    );
    [self.mapView setRegion:region animated:YES];
    
    MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
    annotation.coordinate = coordinate;
    [self.mapView addAnnotation:annotation];
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    if ([annotation isKindOfClass:[MKUserLocation class]]) return nil;
    static NSString *pinID = @"customPin";
    MKPinAnnotationView *pin = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pinID];
    if (!pin) {
        pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pinID];
        pin.pinTintColor = [UIColor redColor];
        pin.animatesDrop = YES;
    } else {
        pin.annotation = annotation;
    }
    return pin;
}




@end
